package org.msfj.admin.org.controller;

import org.msfj.admin.model.UserRole;
import org.msfj.admin.model.UserRole;
import org.msfj.admin.model.UserRole;
import org.msfj.admin.vo.UserRoleVo;
import org.msfj.common.context.UserContextHandler;
import org.msfj.admin.org.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.msfj.common.base.BaseController;
import org.msfj.common.model.CommonResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 系统用户角色关联信息controller
 * @Author: like
 * @Email: like@deyatong.com
 * @Date: 2017-08-10 17:30:21
 * @Version: 1.0
 * @Created in idea by autoCode
 */
@Api(value = "系统用户角色关联信息接口", tags = "系统用户角色关联信息接口")
@RestController
@RequestMapping("org/userRole")
public class UserRoleController extends BaseController{

    @Autowired
    private UserRoleService userRoleService;

    /**
     * 添加系统用户角色关联信息
     *
     * @param userRoleVo
     * @return CommonResult.ok(UserRoleVo)
     */
    @PostMapping("/add")
    @ResponseBody
    @ApiOperation(value = "添加系统用户角色关联信息",notes = "添加系统用户角色关联信息")
    @ApiImplicitParam(value = "userRoleVo",name = "userRoleVo",dataType = "org.msfj.admin.vo.UserRoleVo",paramType = "query")
    public CommonResult addUserRole(UserRoleVo userRoleVo){
        UserRole userRole = userRoleService.saveOrEdit(userRoleVo);
        return CommonResult.ok(userRoleService.setOtherProperties(userRole));
    }

    /**
     * 修改系统用户角色关联信息
     *
     * @param userRoleVo
     * @return CommonResult.ok(UserRoleVo)
     */
    @PostMapping("/edit")
    @ResponseBody
    @ApiOperation(value = "修改系统用户角色关联信息",notes = "修改系统用户角色关联信息")
    @ApiImplicitParam(value = "userRoleVo",name = "userRoleVo",dataType = "org.msfj.admin.vo.UserRoleVo",paramType = "query")
    public CommonResult editUserRole(UserRoleVo userRoleVo){
        UserRole userRole = userRoleService.saveOrEdit(userRoleVo);
        return CommonResult.ok(userRoleService.setOtherProperties(userRole));
    }

    /**
     * 逻辑删除系统用户角色关联信息
     *
     * @param userRoleVo
     * @return CommonResult.ok(UserRoleVo)
     */
    @PostMapping("/del")
    @ResponseBody
    @ApiOperation(value = "逻辑删除系统用户角色关联信息",notes = "逻辑删除系统用户角色关联信息")
    @ApiImplicitParam(value = "userRoleVo",name = "userRoleVo",dataType = "org.msfj.admin.vo.UserRoleVo",paramType = "query")
    public CommonResult delUserRole(UserRoleVo userRoleVo){
        UserRole userRole = userRoleService.delById(userRoleVo);
        return CommonResult.ok(userRoleService.setOtherProperties(userRole));
    }

    /**
     * 逻辑删除系统用户信息
     * @param ids
     * @return CommonResult.ok()
     */
    @PostMapping("/dels")
    @ResponseBody
    @ApiOperation(value = "逻辑删除系统用户角色关联信息",notes = "逻辑删除系统用户角色关联信息")
    @ApiImplicitParam(value = "ids",name = "ids",dataType = "java.util.List",paramType = "query")
    public CommonResult delUsers(@RequestParam("ids[]") List<String> ids){
        UserRole userRole = new UserRole();
        userRoleService.delByIds(ids, userRole);
        return CommonResult.ok();
    }

    /**
     * 真实删除系统用户角色关联信息
     *
     * @param userRoleVo
     * @return CommonResult.ok()
     */
    @PostMapping("/delete")
    @ResponseBody
    @ApiOperation(value = "真实删除系统用户角色关联信息",notes = "真实删除系统用户角色关联信息")
    @ApiImplicitParam(value = "userRoleVo",name = "userRoleVo",dataType = "org.msfj.admin.vo.UserRoleVo",paramType = "query")
    public CommonResult deleteUserRole(UserRoleVo userRoleVo){
        userRoleService.trueDelById(userRoleVo);
        return CommonResult.ok();
    }

    /**
     * 根据id查找系统用户角色关联信息
     *
     * @param userRoleVo
     * @return CommonResult.ok(UserRoleVo)
     */
    @GetMapping("/get")
    @ResponseBody
    @ApiOperation(value = "根据id查找系统用户角色关联信息",notes = "根据id查找系统用户角色关联信息")
    @ApiImplicitParam(value = "userRoleVo",name = "userRoleVo",dataType = "org.msfj.admin.vo.UserRoleVo",paramType = "query")
    public CommonResult getUserRole(UserRoleVo userRoleVo){
        UserRole userRole = userRoleService.getById(userRoleVo.getId());
        return CommonResult.ok(userRoleService.setOtherProperties(userRole));
    }

    /**
     * 根据翻页参数、搜索参数查找系统用户角色关联信息
     *
     * @param userRoleVo
     * @param page 当前第几页
     * @param rows 每页多少条记录
     * @return CommonResult.ok(PageInfo<UserRoleVo>)
     */
    @GetMapping("/list")
    @ResponseBody
    @ApiOperation(value = "根据翻页参数、搜索参数查找系统用户角色关联信息",notes = "根据翻页参数、搜索参数查找系统用户角色关联信息")
    @ApiImplicitParams({
        @ApiImplicitParam(value = "userRoleVo",name = "userRoleVo",dataType = "org.msfj.admin.vo.UserRoleVo",paramType = "query"),
        @ApiImplicitParam(name = "page",value = "page",dataType = "Integer",paramType = "path"),
        @ApiImplicitParam(name = "rows",value = "rows",dataType = "Integer",paramType = "path")
    })
    public CommonResult findUserRoleList(UserRoleVo userRoleVo, Integer page, Integer rows){
        PageInfo<UserRoleVo> userRoleVoPageInfo = userRoleService.getByUserRole(userRoleVo,page,rows);
        return CommonResult.ok(userRoleVoPageInfo);
    }

    /**
     * 根据搜索参数查找所有系统用户角色关联信息
     *
     * @param userRoleVo
     * @return CommonResult.ok(List<UserRoleVo>)
     */
    @GetMapping("/getAll")
    @ResponseBody
    @ApiOperation(value = "根据搜索参数查找所有系统用户角色关联信息",notes = "根据搜索参数查找所有系统用户角色关联信息")
    @ApiImplicitParam(value = "userRoleVo",name = "userRoleVo",dataType = "org.msfj.admin.vo.UserRoleVo",paramType = "query")
    public CommonResult getAllUserRole(UserRoleVo userRoleVo){
        List<UserRoleVo> userRoleVoList = userRoleService.getAllUserRole(userRoleVo);
        return CommonResult.ok(userRoleVoList);
    }

    /**
     * 批量添加系统角色用户关联信息
     * @param roleId
     * @param userIds
     * @return
     */
    @PostMapping("/addList")
    @ResponseBody
    @ApiOperation(value = "添加系统角色用户关联信息", notes = "添加系统角色用户关联信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "roleId", name = "roleId", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(value = "userIds", name = "userIds", dataType = "java.util.List", paramType = "query")
    })
    public CommonResult addRoleMenu(String roleId, @RequestParam(value = "userIds[]",required = false) List<String> userIds) {
        userRoleService.saveListByUserRole(roleId, userIds, UserContextHandler.getUserID());
        return CommonResult.ok();
    }
}
